home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / SCRIPT.PAK / ED_DFLT.SPP < prev    next >
Text File  |  1997-05-06  |  13KB  |  481 lines

  1. //----------------------------------------------------------------------------
  2. // cScript
  3. // (C) Copyright 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. // ED_DFLT.SPP
  6. //    Script component of IDE's Editor Default emulation.
  7. //    Provides support services for editing environment.
  8. //
  9. // $Revision:   1.8  $
  10. //
  11. //----------------------------------------------------------------------------
  12. // Default Editor.
  13. //----------------------------------------------------------------------------
  14.  
  15. //----------------------------------------------------------------------------
  16. // Symbol Imports
  17. //----------------------------------------------------------------------------
  18.  
  19. import IDE;
  20. import editor;
  21. import scriptEngine;
  22. import bFileLoading;
  23.  
  24. //
  25. // Mark this module as being a library module.
  26. //
  27. library;
  28.  
  29. //----------------------------------------------------------------------------
  30. // Symbol Defines
  31. //----------------------------------------------------------------------------
  32.  
  33. #define BOOKMARK_ID_SYSTEM_ONE   19
  34. #define BOOKMARK_ID_SYSTEM_TWO   18
  35. #define BOOKMARK_ID_SYSTEM_THREE 17
  36. #define FUNCTION_CONTINUE 0
  37. #define FUNCTION_END      1
  38.  
  39. //----------------------------------------------------------------------------
  40. // Menu Vectors.
  41. //----------------------------------------------------------------------------
  42.  
  43. DoIDEFileClose()      { return FUNCTION_CONTINUE; }
  44. DoIDEFileOpen()       { return FUNCTION_CONTINUE; }
  45. DoIDEFilePrint()      { return FUNCTION_CONTINUE; }
  46. DoIDEFileSave()       { return FUNCTION_CONTINUE; }
  47. DoIDEFileSaveAs()     { return FUNCTION_CONTINUE; }
  48. DoIDEFileSaveAll()    { return FUNCTION_CONTINUE; }
  49.  
  50. DoIDEEditUndo()       { editor.Undo(); return FUNCTION_END; }
  51. DoIDEEditRedo()       { editor.Redo(); return FUNCTION_END; }
  52. DoIDEEditCut()        { editor.InternalCut(); return FUNCTION_END; }
  53. DoIDEEditCopy()       { editor.Copy(); return FUNCTION_END;  }
  54. DoIDEEditPaste()      { editor.Paste(); return FUNCTION_END; }
  55. DoIDEEditClear()      { editor.InternalDelete(); return FUNCTION_END; }
  56. DoIDEEditSelectAll()  { editor.SelectAll(); return FUNCTION_END; }
  57. DoIDEEditBufferList() { return FUNCTION_CONTINUE; }
  58.  
  59. DoIDESearchFind()     { return FUNCTION_CONTINUE;}
  60. DoIDESearchReplace()  { return FUNCTION_CONTINUE; }
  61. DoIDESearchSearchAgain() { return FUNCTION_CONTINUE; }
  62.  
  63. DoIDESearchPreviousMessage() { return FUNCTION_CONTINUE; }
  64. DoIDESearchNextMessage()     { return FUNCTION_CONTINUE; }
  65.  
  66. //----------------------------------------------------------------------------
  67. // Methods.
  68. //----------------------------------------------------------------------------
  69.  
  70. //
  71. // Used to autoload the Default emulation specific methods.
  72. //
  73. defaultEmulation(bUnassign) {
  74.  
  75.    IDE.KeyboardManager.ScriptAbortKey = "<Escape>";
  76.    IDE.KeyboardManager.ProcessKeyboardAssignments(scriptEngine.StartupDirectory+IDE.KeyboardAssignmentFile,bUnassign);
  77.  
  78.    if (bUnassign) {
  79.       print "Default emulation removed.";
  80.       scriptEngine.Unload(typeid(module()));
  81.    } else {
  82.       print "Default emulation enabled.";
  83.    }
  84. }
  85.  
  86. //----------------------------------------------------------------------------
  87. // Methods.
  88. //----------------------------------------------------------------------------
  89.  
  90. //
  91. // Uses Internal specific behavior for deletion of the current block.
  92. //
  93. on editor:>InternalBlockStyleChange(declare newStyle) {
  94.    SetBlockStyle(newStyle);
  95. }
  96.  
  97. //
  98. // Delete the current block.
  99. //
  100. on editor:>InternalCut() {
  101.    declare eb = .BlockExists();
  102.    if (eb != NULL) {
  103.       declare ev = .TopView;
  104.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  105.       eb.Cut();
  106.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  107.    }
  108. }
  109.  
  110. //
  111. // Uses Internal specific behavior for deletion of the current block.
  112. //
  113. on editor:>InternalDelete() {
  114.    declare eb = .BlockExists();
  115.    if (eb != NULL) {
  116.       if (eb.Size != 0) {
  117.           declare ep = .TopView.Position;
  118.           eb.Save();
  119.           ep.Move(eb.StartingRow,eb.StartingColumn);
  120.           eb.Restore();
  121.           declare rv = eb.Delete();
  122.           ResetBlock(EXCLUSIVE_BLOCK);
  123.           IDE.StatusBar = "Block deleted";
  124.           return rv;
  125.        }
  126.    }
  127.    return 0;
  128. }
  129.  
  130. on editor:>InternalDeleteWordRight() {
  131.  
  132.    declare nBlocked = FALSE;
  133.    declare eb = .BlockExists();
  134.    declare ev = .TopView;
  135.    declare ep = ev.Position;
  136.  
  137.    if (eb != NULL) {
  138.       eb.Save();
  139.       ep.Save();
  140.       ep.Move(eb.StartingRow,eb.StartingColumn);
  141.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  142.       ep.Move(eb.EndingRow,eb.EndingColumn);
  143.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  144.       ep.Restore();
  145.       eb.Restore();
  146.       nBlocked = TRUE;
  147.    }
  148.  
  149.    eb = ResetBlock(EXCLUSIVE_BLOCK);
  150.    eb.Begin();
  151.  
  152.    declare nSpaceAdjust = 0;
  153.    ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_THREE);
  154.  
  155.    if (ep.IsWhiteSpace) {
  156.  
  157.       if (ep.Character == '\t') {
  158.           declare c = ep.Column;
  159.           ep.Delete(1);
  160.           if (ep.Column != c)
  161.              nSpaceAdjust = c - ep.Column;
  162.       }
  163.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  164.    } else if (ep.IsWordCharacter) {
  165.       ep.MoveCursor(SKIP_RIGHT | SKIP_WORD);
  166.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  167.    } else if (ep.IsSpecialCharacter) {
  168.       ep.Delete(1);
  169.       ep.MoveCursor(SKIP_RIGHT | SKIP_WHITE);
  170.    } else
  171.       ep.Delete(1);
  172.  
  173.    eb.End();
  174.    eb.Delete();
  175.  
  176.    ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_THREE);
  177.  
  178.    while (nSpaceAdjust--) {
  179.       ep.InsertText(' ');
  180.    }
  181.  
  182.    if (nBlocked) {
  183.       SetBlockStyle(EXCLUSIVE_BLOCK);
  184.       ep.Save();
  185.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  186.       eb.Begin();
  187.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  188.       eb.End();
  189.       ep.Restore();
  190.    }
  191. }
  192.  
  193. //
  194. // Uses Internal specific behavior for deletion of the current word.
  195. //
  196. on editor:>InternalDeleteWordLeft() {
  197.  
  198.    declare eb = .BlockExists();
  199.    eb = ResetBlock(EXCLUSIVE_BLOCK);
  200.    eb.End();
  201.  
  202.    declare ep = .TopView.Position;
  203.  
  204.    ep.MoveCursor(SKIP_LEFT | SKIP_NONWORD);
  205.    ep.MoveCursor(SKIP_LEFT | SKIP_WORD);
  206.  
  207.    eb.Begin();
  208.  
  209.    eb.Cut();
  210. }
  211.  
  212. //
  213. // Uses Internal specific behavior to toggle current character/block.
  214. //
  215. on editor:>InternalToggleCase() {
  216.    declare eb = .BlockExists();
  217.    if (eb != NULL) {
  218.       eb.ToggleCase();
  219.    } else {
  220.       declare ep = .TopView.Position;
  221.       ep.Save();
  222.       ep.MoveEOL();
  223.       declare x = ep.Column;
  224.       ep.Restore();
  225.       if (x <= ep.Column) {
  226.          ep.Move(ep.Row+1,1);
  227.       } else {
  228.          eb = .TopView.Block;
  229.          eb.Begin();
  230.          ep.MoveRelative(0,1);
  231.          eb.End();
  232.          eb.ToggleCase();
  233.          eb.Reset();
  234.       }
  235.    }
  236. }
  237.  
  238. //
  239. // Uses Default specific behavior to delete a line.
  240. //
  241. on editor:>InternalDeleteLine() {
  242.  
  243.    declare bBlock = FALSE;
  244.    declare eb = .BlockExists();
  245.    declare ev = .TopView;
  246.    declare ep = ev.Position;
  247.  
  248.    if (eb != NULL) {
  249.       eb.Save();
  250.       ep.Save();
  251.       ep.Move(eb.StartingRow,eb.StartingColumn);
  252.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  253.       ep.Move(eb.EndingRow,eb.EndingColumn);
  254.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  255.       ep.Restore();
  256.       eb.Restore();
  257.       bBlock = TRUE;
  258.    } else
  259.       eb = .TopView.Block;
  260.  
  261.    ep.MoveBOL();
  262.    ep.Save();
  263.    BeginBlock(EXCLUSIVE_BLOCK);
  264.  
  265.    if (ep.Row == ep.LastRow)
  266.       ep.MoveEOL();
  267.    else
  268.       ep.MoveRelative(1,0);
  269.  
  270.    EndBlock(EXCLUSIVE_BLOCK);
  271.    eb.Delete();
  272.    ep.Restore();
  273.  
  274.    if (bBlock) {
  275.       SetBlockStyle(EXCLUSIVE_BLOCK);
  276.       ep.Save();
  277.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  278.       eb.Begin();
  279.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  280.       eb.End();
  281.       ep.Restore();
  282.    }
  283. }
  284.  
  285. //
  286. // Uses Default specific behavior to mark to the begining of the file.
  287. //
  288. on editor:>InternalMarkToBOF() {
  289.    declare eb = .TopView.Block;
  290.    declare ep = .TopView.Position;
  291.    if ((eb.StartingRow == ep.Row) && (eb.StartingColumn == ep.Column)) {
  292.       SetBlockStyle(EXCLUSIVE_BLOCK);
  293.       ep.Move(eb.EndingRow,eb.EndingColumn);
  294.       eb.End();
  295.       ep.Move(1,1);
  296.       eb.Begin();
  297.    } else {
  298.       eb.Reset();
  299.       SetBlockStyle(EXCLUSIVE_BLOCK);
  300.       eb.End();
  301.       ep.Move(1,1);
  302.       eb.Begin();
  303.    }
  304. }
  305.  
  306. //
  307. // Uses Default specific behavior to mark to the end of the file.
  308. //
  309. on editor:>InternalMarkToEOF() {
  310.    declare eb = .TopView.Block;
  311.    declare ep = .TopView.Position;
  312.    if ((eb.EndingRow == ep.Row) && (eb.EndingColumn == ep.Column)) {
  313.       SetBlockStyle(EXCLUSIVE_BLOCK);
  314.       ep.Move(eb.StartingRow,eb.StartingColumn);
  315.       eb.Begin();
  316.       ep.MoveEOF();
  317.       eb.End();
  318.    } else {
  319.       eb.Reset();
  320.       SetBlockStyle(EXCLUSIVE_BLOCK);
  321.       eb.Begin();
  322.       ep.MoveEOF();
  323.       eb.End();
  324.    }
  325. }
  326.  
  327. //
  328. // Uses Default specific behavior to mark to the begining of the line.
  329. //
  330. on editor:>InternalMarkToBOL() {
  331.    declare eb = .BlockExists();
  332.     
  333.    if (eb == NULL)
  334.       ResetBlock();
  335.  
  336.   .MarkToBOL();
  337. }
  338.  
  339. //
  340. // Uses Default specific behavior to mark to the end of the line.
  341. //
  342. on editor:>InternalMarkToEOL() {
  343.    declare eb = .BlockExists();
  344.     
  345.    if (eb == NULL)
  346.       ResetBlock();
  347.  
  348.   .MarkToEOL();
  349. }
  350.  
  351. //
  352. // Using Internal behaviour moves block.
  353. //
  354. on editor:>InternalMoveBlock() {
  355.    declare eb = .BlockExists();
  356.    if (eb != NULL) {
  357.       declare ev = .TopView;
  358.       declare ep = ev.Position;
  359.       ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  360.       eb.Save();
  361.       ep.Move(eb.StartingRow, eb.StartingColumn);
  362.       eb.Restore();
  363.       eb.Cut();
  364.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  365.       declare nRow = ep.Row;
  366.       declare nColumn = ep.Column;
  367.       ep.InsertScrap();
  368.       ep.Move(nRow, nColumn);
  369.       eb.Begin();
  370.       ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  371.       eb.Extend(ep.Row, ep.Column);
  372.       eb.Save();
  373.       ep.Move(nRow, nColumn);
  374.       eb.Restore();
  375.    }
  376. }
  377.  
  378. //
  379. // Using Internal behaviour marks and returns the current word.
  380. //
  381. on editor:>InternalMarkWord() {
  382.    declare ep = .TopView.Position;
  383.  
  384.    if (!.TopView.Position.IsWordCharacter) {
  385.       .MoveCursorToWordLeft();
  386.    }
  387.  
  388.    return .MarkWord();
  389. }
  390.  
  391. //
  392. // Using Internal behavior block a line.
  393. //
  394. on editor:>InternalMarkLine() {
  395.  
  396.    declare eb = .BlockExists();
  397.    declare ep = .TopView.Position;
  398.  
  399.    SetBlockStyle(EXCLUSIVE_BLOCK);
  400.  
  401.    if (ep.Column == 1) {
  402.       ep.Save();
  403.  
  404.       if (ep.Row <  ep.LastRow)
  405.          ep.MoveRelative(1,0);
  406.       else
  407.          ep.MoveEOL();
  408.  
  409.       if (eb == NULL)
  410.          eb = .TopView.Block;
  411.  
  412.       ResetBlock();
  413.       eb.End();
  414.       ep.Restore();
  415.       eb.Begin();
  416.    }
  417. }
  418.  
  419. //
  420. // Using Internal behavior perform lower case operation.
  421. //
  422. on editor:>InternalLowerWord() {
  423.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  424.    if (!.TopView.Position.IsWordCharacter) {
  425.       .MoveCursorToWordLeft();
  426.    }
  427.    .MarkWord().LowerCase();
  428.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  429.    .TopView.Block.Reset();
  430. }
  431.  
  432. //
  433. // Using Internal behavior perform lower case operation.
  434. //
  435. on editor:>InternalUpperWord() {
  436.    .TopView.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  437.    if (!.TopView.Position.IsWordCharacter) {
  438.       .MoveCursorToWordLeft();
  439.    }
  440.    .MarkWord().UpperCase();
  441.    .TopView.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  442.    .TopView.Block.Reset();
  443. }
  444.  
  445. //
  446. // Using Internal behavior perform block copy operation.
  447. //
  448. on editor:>InternalCopyBlock() {
  449.    declare eb = .BlockExists();
  450.    if (eb != NULL) {
  451.       declare ev = .TopView;
  452.       declare ep = ev.Position;
  453.       if (StartBlockBeforeCursor(eb,ep)) {
  454.          eb.Copy();
  455.          ep.Move(eb.StartingRow,eb.StartingColumn);
  456.          ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_ONE);
  457.          ep.Move(eb.EndingRow,eb.EndingColumn);
  458.          ev.BookmarkRecord(BOOKMARK_ID_SYSTEM_TWO);
  459.          ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  460.          .TopView.Position.InsertScrap();
  461.          ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  462.          eb.Begin();
  463.          ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_TWO);
  464.          eb.End();
  465.          ev.BookmarkGoto(BOOKMARK_ID_SYSTEM_ONE);
  466.       } else {
  467.          ep.Save();
  468.          eb.Save();
  469.          eb.Copy();
  470.          eb.Reset();
  471.          .TopView.Position.InsertScrap();
  472.          ep.Restore();
  473.          eb.Restore();
  474.       }
  475.       IDE.StatusBar = "Block copied";
  476.  
  477.    } else {
  478.       IDE.ReportError("No marked block");
  479.    }
  480. }
  481.